/**
 * 
 */
package com.vnetoo.osfilesvr;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;



/**
 * @author chenh
 *
 */
public class FileServer {

	private static final Logger log=Logger.getLogger(FileServer.class);
	public static boolean FILE_LOG=false;
		
	public FileServer(int serverPort,int maxConNum,int timeOut,boolean fileLog) throws IOException{
		FILE_LOG=fileLog;
		ServerSocket serverSocket=new ServerSocket(serverPort,maxConNum);
		
		if(log.isInfoEnabled())
			log.info("FileServer start at "+
				 serverSocket.getInetAddress().getHostAddress()+":"+serverPort);
		
		Socket clientSocket=null;
		while (true) {			
			clientSocket = serverSocket.accept();			
			clientSocket.setSoTimeout(timeOut);

			if(log.isInfoEnabled())
				log.info("Connection from: " + clientSocket);
					
			
			Thread thread = new Thread(new ServerThread(clientSocket));
			thread.start();
		}
	}
}
